/**
 * Created by Gaojf on 2017/3/25.
 */
module.exports = function ($http, $q, httpservice, $cookies){
  var service = {
    lawfirm:lawfirm,
    queryUser:queryUser,
    teamList:teamList,
    getTeamMember:getTeamMember,
    teamUpdate:teamUpdate,
    teamInvite:teamInvite,
    teamCreate:teamCreate,
    teamAssign:teamAssign,
    teamRemove:teamRemove,
    teamQuit:teamQuit,
    addMember:addMember,
    teamCaseList:teamCaseList,
    lawCaseList:lawCaseList,
    teamGetMemberSingleUrl:teamGetMemberSingleUrl,
    teamInviteMemberSingleUrl:teamInviteMemberSingleUrl,
    teamtasklist:teamtasklist,
    searchLawfirmMember: searchLawfirmMember,
    teamMemberRemove: teamMemberRemove
  };
  return service;
  //团队左侧律所列表
  function queryUser() {
    return $http({
      url:httpservice.queryUserInfoUrl,
      method:"get"
    })
  }
  //律所成员
  function lawfirm(params) {
    return $http({
      url:httpservice.lawfirmUrl,
      method:"POST",
      params:params
    })
  }
  //左侧团队列表
  function teamList() {
    return $http({
      url:httpservice.teamlistUrl,
      method:"POST"
    })
  }

  //团队成员
  function getTeamMember(params) {
    return $http({
      url:httpservice.getTeamMemberUrl,
      method:"POST",
      params:params
    })
  }

  //更新团队信息
  function teamUpdate(params) {
    return $http({
      url:httpservice.updateUrl,
      method:"POST",
      params:params
    })
  }

  //邀请成员
  function teamInvite(params) {
    return $http({
      url:httpservice.inviteUrl,
      method:"POST",
      params:params
    })
  }
  //转让团队
  function teamAssign(params) {
    return $http({
      url:httpservice.assignUrl,
      method:"POST",
      params:params
    })
  }
  //解散团队
  function teamRemove(params) {
    return $http({
      url:httpservice.removeUrl,
      method:"POST",
      params:params
    })
  }
  //删除团队成员
  function teamMemberRemove(params) {
    return $http({
      url:httpservice.deleteTeamMemberUrl,
      method:"POST",
      params:params
    })
  }


  //退出团队
  function teamQuit(params) {
    return $http({
      url:httpservice.quitUrl,
      method:"POST",
      params:params
    })
  }

  //创建团队
  function teamCreate(params) {
    return $http({
      url:httpservice.createUrl,
      method:"POST",
      params:params
    })
  }
  //添加成员
  function addMember(params) {
    return $http({
      url:httpservice.byUserNameUrl,
      method:"POST",
      params:params
    })
  }
  //添加成员
  function addMember(params) {
    return $http({
      url:httpservice.byUserNameUrl,
      method:"POST",
      params:params
    })
  }
  //团队案件列表
  function teamCaseList(params) {
    return $http({
      url:httpservice.caseListUrl,
      method:"POST",
      params:params
    })
  }

  //律所案件列表
  function lawCaseList(params) {
    return $http({
      url:httpservice.caseListByLawfirmUrl,
      method:"GET",
      params:params
    })
  }

  //添加成员时检索用户信息
  function teamGetMemberSingleUrl(params) {
    return $http({
      url:httpservice.teamGetMemberSingleUrl,
      method:"GET",
      params:params
    })
  }

  //检索后的用户进行添加到team
  function teamInviteMemberSingleUrl(params) {
    return $http({
      url:httpservice.inviteUrl,
      method:"GET",
      params:params
    })
  }

  //检索后的用户进行添加到律所
  function lawFirmInviteMemberSingleUrl(params) {
    return $http({
      url:httpservice.inviteUrl,
      method:"GET",
      params:params
    })
  }

  //搜索律所用户
  function searchLawfirmMember(params) {
    return $http({
      url: httpservice.searchLawfirmMemberUrl,
      method: "POST",
      params: params
    })
  }

  /**
   * 团队日程任务
   * @param id
   * @param selectedUsers
   * @returns {Function}
   */
  function teamtasklist(id, selectedUsers, teamId) {
    var params={"bigLawuserid":id, "selectedUsers":selectedUsers, "teamId":teamId};
    var deferred = $q.defer();
    $http({
      method: 'POST',
      url: httpservice.teamCalendarTaskUrl,
      data:params,
      //  headers: {'Content-Type': 'application/x-www-form-urlencoded'}
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;
  };

};
